package com.dbsop.common.enums;

import java.util.Collection;
import java.util.Date;
import java.util.List;

public enum TypeEnum {
    STRING(String.class,"keyword"),
    INTEGER(Integer.class,"integer"),
    BYTE(Byte.class,"byte"),
    LONG(Long.class,"long"),
    DATE(Date.class,"date"),
    DOUBLE(Double.class,"double"),
    FLOAT(Float.class,"float"),
    BOOLEAN(Boolean.class,"boolean"),
    LIST(Collection.class,null),
    OBJECT(Object.class,"object");
    private Class  baseType;
    private String esType;

    TypeEnum(Class baseType, String esType) {
        this.baseType = baseType;
        this.esType = esType;
    }


    public static TypeEnum getTypeEnumByClass(Class clazz){
        TypeEnum[] values = TypeEnum.values();
        for (TypeEnum value : values) {
            if (value.getBaseType().isAssignableFrom(clazz)) {
                return value;
            }
        }
        return null;
    }

    public Class getBaseType() {
        return baseType;
    }

    public void setBaseType(Class baseType) {
        this.baseType = baseType;
    }

    public String getEsType() {
        return esType;
    }

    public void setEsType(String esType) {
        this.esType = esType;
    }
}
